from django import forms

from DjangoUeditor.forms import UEditorModelForm
from accounts.models import Department_Mode, CustomUser
from malfunctions.models import Incident

BOOL_STATUS = ((True, '是'), (False, '否'))


class MalfunctionCreateForm(UEditorModelForm):
    """
        故障表单
    """
    op = [("--------------", "--------------")]
    try:
        op_group = Department_Mode.objects.get(desc_gid=1001)  # todo  硬编码   1001运维部
        op_user = CustomUser.objects.filter(department=op_group)

        for i in op_user:
            op.append((i.username, i.username))
    except:
        pass

    project_status = forms.ChoiceField(widget=forms.RadioSelect, choices=BOOL_STATUS, required=True, initial=True,
                                       label="是否通知项目负责人")
    projectuser = forms.CharField(max_length=32, widget=forms.Select(choices=op), label="业务负责人")

    class Meta:
        model = Incident
        fields = ['title', 'source', 'url', 'grade',
                  'mailcomment',
                  'starttime', 'scantime', 'stoptime', 'projectuser',
                  'comment',
                  'status', 'classical', 'project_principal', "project_status"
                  ]


class MalfunctionHandleForm(UEditorModelForm):
    """处理故障"""

    class Meta:
        model = Incident
        fields = ['title', 'source', 'url', 'grade', 'mailcomment', 'starttime', 'scantime', 'stoptime', 'projectuser',
                  'comment', 'status', 'classical', 'project_principal'
                  ]
